Skip to content

refactor(NODE-5741): use async io helpers #3930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Dec 4, 2023
Merged

Conversation

nbbeeken
Copy link
Contributor

Description

What is changing?

Note reviewing per commit will assist greatly with following the changes made:

  • test: latest lts avoiding npm install issue
    • npm latest needs 18.17 or later
  • test: fix spec auth test to spy on correct connection class
    • the speculative auth tests spied on Connection.command, I adjusted it to spy on ModernConnection when they are enabled
  • test: session usage back down to 1! woo!
    • I suspected this would happen! Session usage is back down to 1 for maxPoolSize 1. This has to do with callbacks having inconsistent asynchronicity vs promises being consistently ordered
  • test: fix utf8 validation option tests
    • The utf8 validation tests spied on onMessage which no longer exists. They can just as easily assert the same thing if they spy on the method that parses the utf8 bson options
  • test: set env variable for new connection tests
    • An environment variable controls passing ModernConnection into the MongoClient constructor in newClient, this may not be 100% coverage, but substantial enough to get us to the next PRs where we will switch over to one connection class entirely.
  • refactor: re-introduce listeners for signal aborting with error
    • I mistakenly removed these, the listeners hook up to controller.abort()
  • test: add new variants enabling ModernConnection
    • New build variant that defines the env variable that will make the driver test with ModernConnection
  • refactor: connect error handling to signal
    • The Connection class now has a controller property set to an AbortController instance
    • The read and write helpers are given the signal from this controller
    • timeout and close events will abort the controller, which will interrupt the I/O operations if they are in progress
    • An AbortError will have its cause set to one of our MongoError subclasses which the operation handler will extract
  • refactor: remove drain event listener
    • The drain event only emits if the stream has to buffer the data to be written, the way to determine if data has been buffered is by inspecting the return value of .write
    • Since we have to call write to determine if we need to wait for drain, I think it is equivalent for us to await the .write's callback
  • refactor: remove force flag and support noResponse
    • Added noResponse support, I decided to return ok:1 here, now that we are using promises our types are better and I do not think there is value in having our command method return something nullish
    • Removed the force flag for debugging, can re-introduce but consider:
      • it was easier to reason about the socket's state when a synchronous function marks it as ended the callbackified end function introduced an unnecessary step in finishing the cleanup process.
  • refactor: update cleanup method
    • Updated the cleanup method to simplify the new paradigm of only dealing with a socket and not also a MessageStream
  • The following are self-explanatory helper refactors to organize code
    • refactor: remove message stream
    • refactor: remove onMessage
    • refactor: add sendCommand helper for send and recv
    • refactor: make command async
    • refactor: move command preparing to helper
    • refactor(NODE-5741): use async io helpers
Is there new documentation needed for these changes?

No

What is the motivation for this change?

Migrating I/O to async enables us to use signals. Singals will be an essntial part of CSOT.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@nbbeeken nbbeeken marked this pull request as ready for review November 20, 2023 21:19
Copy link
Contributor

@baileympearson baileympearson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first pass review - didn't look at Connection.ts yet and a few other misc files. Just looked over CI, utils and test changes

@durran durran self-assigned this Nov 21, 2023
nbbeeken and others added 5 commits December 1, 2023 10:44
Co-authored-by: Daria Pardue <daria.pardue@mongodb.com>
Co-authored-by: Daria Pardue <daria.pardue@mongodb.com>
nbbeeken and others added 2 commits December 1, 2023 15:33
Co-authored-by: Daria Pardue <daria.pardue@mongodb.com>
@nbbeeken nbbeeken requested a review from dariakp December 1, 2023 20:56
Co-authored-by: Daria Pardue <daria.pardue@mongodb.com>
@nbbeeken nbbeeken requested a review from dariakp December 1, 2023 22:18
@dariakp dariakp added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Dec 4, 2023
@durran durran merged commit ad2d15c into main Dec 4, 2023
@durran durran deleted the NODE-5741-use-io-async branch December 4, 2023 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants